<template>
  <div class="OrderDetail" v-if="orderDetail">
    <div class="OrderStatus" :style="`backgroundColor:${orderDetail._status._type != -1?'#e93323' : '#666666'}`">
      <img :src="orderDetail.status_pic" alt="" v-if="orderDetail._status._type != -1"/>
      <div class="status_content">
        <p>{{ orderDetail._status._msg }}</p>
        <p>{{ orderDetail._pay_time }}</p>
      </div>
    </div>
    <div class="OrderProgress">
      <van-steps
        :active="orderDetail._status._type"
        active-color="#fc4141"
        inactive-color="#939390"
        v-if="orderDetail._status._type != -1"
      >
        <van-step>待付款</van-step>
        <van-step>待发货</van-step>
        <van-step>待收货</van-step>
        <van-step>待评价</van-step>
        <van-step>已完成</van-step>
      </van-steps>
      <div class="orderAddress">
        <div>
          <span>{{ orderDetail.real_name }}</span>
          <span>{{ orderDetail.user_phone }}</span>
        </div>
        <div>{{ orderDetail.user_address }}</div>
      </div>
    </div>
    <div class="OrderProduct">
      <p class="product_num">共{{ orderDetail.cartInfo.length }}件商品</p>
      <div
        class="product_params"
        v-for="item in orderDetail.cartInfo"
        :key="item.id"
      >
        <van-image :src="item.productInfo.image"></van-image>
        <div class="params_data">
          <p>{{ item.productInfo.store_name }}</p>
          <span>{{ item.productInfo.attrInfo.suk }}</span>
          <span>￥{{ item.productInfo.price }}</span>
          <span>x{{ item.cart_num }}</span>
        </div>
      </div>
    </div>
    <div class="OrderParams">
      <ul>
        <li>
          <span>订单编号：</span>
          <span>
            {{ orderDetail.order_id }}
            <button @click="Copy">复制</button>
            <input
              type="text"
              :value="orderDetail.order_id"
              style="opacity: 0; position: absolute; top: 0; left: 0"
              ref="input"
            />
          </span>
        </li>
        <li>
          <span>下单时间：</span>
          <span>{{ orderDetail._add_time }}</span>
        </li>
        <li>
          <span>订单类型：</span>
          <span>普通订单</span>
        </li>
        <li>
          <span>支付状态：</span>
          <span>{{ orderDetail._status._title }}</span>
        </li>
        <li>
          <span>支付方式：</span>
          <span>{{ orderDetail._status._payType }}</span>
        </li>
      </ul>
    </div>
    <div class="OrderCloseAccount OrderParams">
      <ul>
        <li>
          <span>支付金额：</span>
          <span>￥{{ orderDetail.total_price }}</span>
        </li>
        <li v-if="Number(orderDetail.deduction_price) != 0">
          <span>积分抵扣：</span>
          <span>-￥{{ orderDetail.deduction_price }}</span>
        </li>
        <li>
          <span>运费：</span>
          <span>￥{{ orderDetail.total_postage }}</span>
        </li>
      </ul>
      <div class="practical">
        <span>实付款：</span>
        <span style="color: red; font-weight: bold"
          >￥{{ orderDetail.pay_price }}</span
        >
      </div>
    </div>
    <div class="OrderOperate" v-if="orderDetail._status._type != -1">
      <template v-if="orderDetail._status._type == 0">
        <div class="cancelOrder" @click="cancelOrder">取消订单</div>
        <div class="complete" @click="payNow(orderDetail.order_id)">立即付款</div>
      </template>
      <template v-else>
        <div class="cancelOrder" @click="applicationdrawback">申请退款</div>
      </template>
    </div>
    <van-action-sheet v-model="paymentShow" title="选择付款方式">
      <div class="content">
        <div class="wx" @click="PayType('weixin')">
          <div class="wx_left">
            <div class="left_icon" style="background:#09bb07;border-radius:50%;padding:3px">
              <van-icon name="wechat" color="white" size="0.4rem" />
            </div>
            <div class="right_text">
              <span>微信支付</span>
              <span>使用微信快捷支付</span>
            </div>
          </div>
          <div class="wx_right">
            <van-icon name="arrow" color="#a8a8a8" size="0.35rem"/>
          </div>
        </div>
        <div class="my" @click="PayType('yue')">
          <div class="my_left">
            <div class="left_icon">
              <van-icon name="gold-coin" color="#fe960f" size="0.5rem" />
            </div>
            <div class="right_text">
              <span>余额支付</span>
              <span>当前可用余额<span></span></span>
            </div>
          </div>
          <div class="my_right">
            <van-icon name="arrow" color="#a8a8a8" size="0.35rem"/>
          </div>
        </div>
      </div>
    </van-action-sheet>
  </div>
</template>

<script>
export default {
  data() {
    return {
      orderDetail: null,
      paymentShow:false
    };
  },
  methods: {
    Copy() {
      this.$refs.input.select();
      document.execCommand("Copy");
      this.$toast({
        message: "复制成功",
      });
    },
    cancelOrder() {
      this.$dialog
        .confirm({
          title: "提示",
          message: "确认取消该订单？",
        })
        .then(() => {
          // on confirm
          this.axios.post("/api/order/cancel",{
            id:this.orderDetail.order_id
          }).then(response=>{
            if(response.data.status == 200){
              this.$router.push('/order/list')
            }
          })
        })
        .catch(() => {
          // on cancel
        });
    },
    payNow(orderId){
      this.paymentShow = true
      this.orderId = orderId;
    },
    PayType(type){
      this.paymentShow = false;
      this.axios.post('/api/order/pay',{
        from: "weixinh5",
        paytype:type,
        uni:this.orderId,
      }).then(response=>{
        if(response.data.status!=200){
          this.$toast(response.data.msg)
        }
      })
    },
    applicationdrawback(){
      this.$router.push({
        path:'/order/refund',
        query:{
          id:this.orderDetail.order_id
        }
      })
    }
  },
  created() {
    this.axios
      .get("api/order/detail/" + this.$route.query.id)
      .then((response) => {
        this.orderDetail = response.data.data;
      });
  },
};
</script>

<style lang="less">
.OrderDetail {
  width: 100%;
  .OrderStatus {
    width: 100%;
    height: 75px;
    background-color: #e93323;
    display: flex;
    align-items: center;
    padding: 0 15px;
    > img {
      width: 50px;
      height: 50px;
    }
    .status_content {
      margin-left: 15px;
      color: white;
      > p {
        &:nth-child(1) {
          font-weight: bold;
          margin-bottom: 5px;
          font-size: 15px;
        }
        &:nth-child(2) {
          font-size: 12px;
          color: rgba(255, 255, 255, 0.6);
        }
      }
    }
  }
  .OrderProgress {
    width: 100%;
    padding: 3px 15px;
    background-color: #fff;
    position: relative;
    &::after {
      content: "";
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 2px;
      background: repeating-linear-gradient(
        -45deg,
        #fe9f86 0,
        #fe9f86 20%,
        transparent 0,
        transparent 25%,
        #95bef9 0,
        #95bef9 45%,
        transparent 0,
        transparent 50%
      );
      background-size: 15%;
    }
    .orderAddress {
      width: 100%;
      margin-top: 10px;
      font-size: 14px;
      > div {
        margin-bottom: 10px;
        > span {
          margin-right: 20px;
        }
        &:nth-child(2) {
          color: #868686;
        }
      }
    }
  }
  .OrderProduct {
    width: 100%;
    margin-top: 10px;
    background-color: #fff;
    padding-bottom: 10px;
    .product_num {
      padding-left: 15px;
      font-size: 14px;
      height: 40px;
      line-height: 40px;
      border-bottom: 1px solid #f2f2f2;
    }
    .product_params {
      width: 100%;
      padding: 10px 15px;
      display: flex;
      .van-image {
        width: 65px;
        height: 65px;
        margin-right: 15px;
      }
      .params_data {
        flex: 1;
        font-size: 14px;
        position: relative;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        > p {
          width: 230px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        span {
          font-size: 12px;
          &:nth-of-type(1),
          &:last-child {
            color: #868686;
          }
          &:nth-of-type(2) {
            font-size: 14px;
            color: #fc4141;
          }
          &:last-child {
            position: absolute;
            top: 0;
            right: 0;
          }
        }
      }
    }
  }
  .OrderParams {
    width: 100%;
    margin-top: 10px;
    background-color: #fff;
    padding: 10px 15px;
    > ul {
      width: 100%;
      > li {
        width: 100%;
        height: 30px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 14px;
        > span {
          position: relative;
          &:nth-child(2) {
            color: #868686;
          }
          > button {
            background-color: #fff;
            outline: none;
            border: 1px solid black;
            margin-left: 5px;
            color: black;
            font-size: 12px;
            padding: 2px 8px;
          }
        }
      }
    }
  }
  .OrderCloseAccount {
    width: 100%;
    margin-bottom: 60px;
    > ul {
      border-bottom: 1px solid #f4f4f4;
    }
    .practical {
      width: 100%;
      height: 40px;
      font-size: 14px;
      line-height: 40px;
      text-align: right;
    }
  }
  .OrderOperate {
    width: 100%;
    height: 50px;
    background-color: #fff;
    position: fixed;
    left: 0;
    bottom: 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0 15px;
    > div {
      width: 80px;
      height: 30px;
      line-height: 30px;
      text-align: center;
      font-size: 14px;
      border-radius: 20px;
      margin-left: 10px;
      &.cancelOrder {
        color: #bdaab2;
        border: 1px solid #bdaab2;
      }
      &.complete {
        color: white;
        background-color: #e93323;
      }
    }
  }
  .van-popup {
    .van-action-sheet__header{
      border-bottom: 1px solid #f5f5f5;
    }
    .van-action-sheet__content{
      padding: 0 10px;
      .content{
        width: 100%;
        padding-bottom: 40px;
        .wx,.my{
          display: flex;
          height: 60px;
          align-items: center;
          justify-content: space-between;
          border-bottom: 1px solid #f5f5f5;
          .wx_left,.my_left{
            display: flex;
            align-items: center;
            .van-icon-wechat{
              display: block;
            }
            .right_text{
              display: flex;
              flex-direction: column;
              margin-left: 10px;
              span{
                &:nth-child(2){
                  font-size: 12px;
                  color: #a7a7a7;
                  margin-top: 3px;
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>